package com.xca.is.componse;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.xca.is.R;

public class BottomView extends LinearLayout {
    private LinearLayout  l1 , l2 , l3 , l4 ;
    private ImageView i1 , i2 , i3 , i4 ;
    private TextView t1 , t2 , t3 , t4 ;

    private LinearLayout[] layouts ;
    private ImageView[] icons ;
    private TextView[] texts ;

    public BottomView(Context context) {
        super(context);
        init();
    }

    public BottomView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init(){
        View view = LayoutInflater.from(getContext()).inflate(R.layout.bottom_view , this , true) ;

        l1 = view.findViewById(R.id.l1);
        l2 = view.findViewById(R.id.l2);
        l3 = view.findViewById(R.id.l3);
        l4 = view.findViewById(R.id.l4);
        i1 = view.findViewById(R.id.i1);
        i2 = view.findViewById(R.id.i2);
        i3 = view.findViewById(R.id.i3);
        i4 = view.findViewById(R.id.i4);
        t1 = view.findViewById(R.id.t1);
        t2 = view.findViewById(R.id.t2);
        t3 = view.findViewById(R.id.t3);
        t4 = view.findViewById(R.id.t4);
        layouts = new LinearLayout[]{l1 , l2 , l3 , l4 };
        icons = new ImageView[]{i1 , i2 , i3 , i4 };
        texts = new TextView[]{t1 , t2 , t3 , t4 };
        i1.setSelected(true);
        t1.setSelected(true);
    }

    public void setBtnClickListener( int index,OnClickListener listener){
        layouts[index].setOnClickListener(listener);
    }

    public void setBtnSelected(int index){
        for (int i = 0 ; i < layouts.length ; i++){
            icons[i].setSelected(i == index);
            texts[i].setSelected(i == index);
        }
    }

}
